package org.example.font.service.impl;

import org.example.font.mapper.DeptMapper;
import org.example.font.model.Dept;
import org.example.font.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public Dept queryDeptByName(String name) {
        return deptMapper.queryByName(name);
    }

    @Override
    public List<Dept> getDepts() {
        return deptMapper.getAll();
    }

    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept queryDeptById(Integer id) {
        return deptMapper.queryById(id);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateById(dept);
    }

    @Override
    public void deleteDeptById(Integer id) {
        deptMapper.deleteById(id);
    }
}
